package com.aspose.cells;

import java.util.ArrayList;
import java.util.Iterator;

class zamq extends zbz {
   private short d;
   private ArrayList e;
   private WorksheetCollection f;
   private zra g;
   private int h;
   private byte[] i;
   private int j;
   ArrayList a;

   zamq(WorksheetCollection var1, int var2) {
      this.c(235);
      this.f = var1;
      this.d = (short)(8224 - var2);
   }

   ArrayList a() {
      return this.e;
   }

   void a(zra var1) {
      this.g = var1;
      int var2 = (int)(var1.h() & 4294967295L);
      this.h = var2 + 8;
      this.j = 0;
      if (var2 + 8 > this.d) {
         this.a(this.d);
         this.e = new ArrayList();
         this.h -= this.d();
      } else {
         this.a((short)(var2 + 8));
         this.h = 0;
      }

      this.c = new byte[this.d()];
      this.i = this.c;
      this.i[this.j] = 15;
      this.i[this.j + 2] = 0;
      this.i[this.j + 3] = -16;
      System.arraycopy(com.aspose.cells.b.a.zc.a(var2), 0, this.i, this.j + 4, 4);
      this.j += 8;
      this.a(var1.d());
      this.b();
      ArrayList var3 = this.g.f();
      if (var3 != null && var3.size() != 0) {
         Iterator var6 = var3.iterator();

         while(var6.hasNext()) {
            byte[] var5 = (byte[])var6.next();
            this.b(var5);
         }
      } else {
         byte[] var4 = new byte[]{51, 0, 11, -16, 18, 0, 0, 0, -65, 0, 8, 0, 8, 0, -127, 1, 9, 0, 0, 8, -64, 1, 64, 0, 0, 8, 64, 0, 30, -15, 16, 0, 0, 0, 13, 0, 0, 8, 12, 0, 0, 8, 23, 0, 0, 8, -9, 0, 0, 16};
         this.b(var4);
      }

      this.i = null;
   }

   void b() {
      zds var1 = this.g.c();
      if (var1 != null && var1.getCount() != 0) {
         byte[] var2 = new byte[8];
         byte var3 = 15;
         int var6 = var3 | var1.getCount() << 4;
         System.arraycopy(com.aspose.cells.b.a.zc.a(var6), 0, var2, 0, 2);
         var2[2] = 1;
         var2[3] = -16;
         System.arraycopy(com.aspose.cells.b.a.zc.a(var1.a()), 0, var2, 4, 4);
         this.b(var2);
         Iterator var4 = var1.iterator();

         while(var4.hasNext()) {
            zcb var5 = (zcb)var4.next();
            var2 = new byte[var5.d() + 8];
            var5.c(var2);
            this.b(var2);
            if (var5.f().e() != null) {
               this.b(var5.f().e());
            }
         }

      }
   }

   void b(byte[] var1) {
      int var2 = 0;
      boolean var3 = false;
      boolean var4 = false;

      while(true) {
         int var5 = var1.length - var2;
         if (var5 > this.i.length - this.j) {
            var5 = this.i.length - this.j;
            var4 = true;
         } else {
            var4 = false;
         }

         System.arraycopy(var1, var2, this.i, this.j, var5);
         var2 += var5;
         if (!var4) {
            this.j += var5;
            if (this.j == this.i.length) {
               this.c();
            }

            return;
         }

         this.j = this.i.length;
         this.c();
      }
   }

   void a(zqz var1) {
      this.i[this.j + 2] = 6;
      this.i[this.j + 3] = -16;
      System.arraycopy(com.aspose.cells.b.a.zc.a(var1.a()), 0, this.i, this.j + 4, 4);
      this.j += 8;
      System.arraycopy(com.aspose.cells.b.a.zc.a(var1.b().a), 0, this.i, this.j, 4);
      this.j += 4;
      System.arraycopy(com.aspose.cells.b.a.zc.a(var1.c().size() + 1), 0, this.i, this.j, 4);
      this.j += 4;
      System.arraycopy(com.aspose.cells.b.a.zc.a(var1.b().b), 0, this.i, this.j, 4);
      this.j += 4;
      System.arraycopy(com.aspose.cells.b.a.zc.a(var1.b().c), 0, this.i, this.j, 4);
      this.j += 4;
      Iterator var2 = var1.c().iterator();

      while(true) {
         do {
            if (!var2.hasNext()) {
               return;
            }

            zva var3 = (zva)var2.next();
            System.arraycopy(com.aspose.cells.b.a.zc.a(var3.a), 0, this.i, this.j, 4);
            System.arraycopy(com.aspose.cells.b.a.zc.a(var3.b), 0, this.i, this.j + 4, 4);
            this.j += 8;
         } while(this.j != this.i.length && this.j + 8 <= this.i.length);

         this.c();
      }
   }

   void c() {
      if (this.j < this.i.length) {
         this.h += this.i.length - this.j;
      }

      if (this.a == null) {
         this.a = new ArrayList();
      }

      com.aspose.cells.b.a.a.ze.a(this.a, (Object)this.j);
      if (this.h != 0) {
         if (this.h <= this.d) {
            this.i = new byte[this.h];
            this.h = 0;
         } else {
            this.i = new byte[this.d];
            this.h -= this.d;
         }

         com.aspose.cells.b.a.a.ze.a(this.e, (Object)this.i);
         this.j = 0;
      }
   }

   void a(zqa var1) throws Exception {
      int var2 = this.a == null ? this.d() : (Integer)this.a.get(0);
      var1.a(this.f());
      var1.a((short)var2);
      var1.a(this.c);
      if (this.e != null) {
         for(int var3 = 0; var3 < this.e.size(); ++var3) {
            byte[] var4 = (byte[])((byte[])this.e.get(var3));
            if (var3 + 1 < this.a.size()) {
               var2 = (Integer)this.a.get(var3 + 1);
            } else {
               var2 = var4.length;
            }

            var1.c(60);
            var1.a((short)var4.length);
            var1.a(var4);
         }
      }

   }
}
